var constant = require('../common/constant');
homeService.$inject=['$http'];

function homeService($http){
    return {
        getMerchantMsg:getMerchantMsg,
        getStatus:getStatus,
        applyStore:applyStore
    }

    function getMerchantMsg(callback){
        var baseUrl = constant.BaseUrl;
        $http.get(baseUrl+'/sec/merchant')
            .then(function successCallback(response) {
                callback(response);
            }, function errorCallback(response) {
                // 请求失败执行代码
                callback(response);
            });
    }

    function getStatus(callback){
        var baseUrl = constant.BaseUrl;
        $http.get(baseUrl+'/sec/status')
            .then(function successCallback(response) {
                callback(response);
            }, function errorCallback(response) {
                // 请求失败执行代码
                callback(response);
            });
    }

    function applyStore(data,callback) {
        var baseUrl = constant.BaseUrl;
        var fd = new FormData();
        for(var key in data)
            fd.append(key, data[key]);
        $http.put(baseUrl+'/sec/merchant', fd, {
            transformRequest: angular.indentity,
            headers: { 'Content-Type': undefined }
        }).then(function successCallback(response) {
                callback(response);
            }, function errorCallback(response) {
                // 请求失败执行代码
                callback(response);
            });
    }


}

module.exports = homeService;
